<?php

namespace App\Http\Controllers;

use App\CourseSignup;
use App\Course;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class CourseSignupController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index($id)
    {
        if (Course::find($id)->club_id != Auth::user()->club_id)
            abort('403');

        $signlist = Course::find($id)->signlist;
        foreach ($signlist as $key ) {
            // Query Username from Users
            $key->gender = User::find($key->user_id)->gender;
            $key->birthdate = User::find($key->user_id)->birthdate;
            $key->tel = User::find($key->user_id)->tel;
            $key->username = User::find($key->user_id)->real_name;
        }

        return view('courses.signup_list',\compact('signlist'));
    }
}
